﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using System.Collections;

namespace DAO
{
    public static class ChiTietCongViec_DAO
    {
        private static QLTDTVDataContext dt = new QLTDTVDataContext();
        public static List<ChiTietCongViec_DTO> DanhSachCacCongViecThuocNganhNghe(string Mng)
        {

            var list = dt.spDanhSachCacCongViecThuocNganhNghe(Mng);
            List<ChiTietCongViec_DTO> DSCongViec = new List<ChiTietCongViec_DTO>();
            try
            {
                foreach (var cv in list)
                {
                    ChiTietCongViec_DTO congviec = new ChiTietCongViec_DTO();
                    congviec.MaCongViec = cv.MaCongViec;
                    congviec.TenCongTy = cv.TenCongTy;
                    congviec.ChucDanh = cv.ChucDanh;
                    congviec.NoiLamViec = cv.Ten;
                    congviec.NgayDang = (DateTime)cv.NgayDang;
                    congviec.Mucluong = cv.MucLuong;
                    congviec.MaCongTy = (int)cv.MaNhaTuyenDung;
                    congviec.MaNoiLamViec = (int)cv.MaTinhThanh;
                    DSCongViec.Add(congviec);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return DSCongViec;
        }

        public static List<ChiTietCongViec_DTO> DanhSachCacCongViecThuocNhaTuyenDung(string Mct)
        {
            var list = dt.spDanhSachCacCongViecThuocNhaTuyenDung(Mct);
            List<ChiTietCongViec_DTO> DSCongViec = new List<ChiTietCongViec_DTO>();
            try
            {
                foreach (var cv in list)
                {
                    ChiTietCongViec_DTO congviec = new ChiTietCongViec_DTO();
                    congviec.MaCongViec = cv.MaCongViec;
                    congviec.TenCongTy = cv.TenCongTy;
                    congviec.ChucDanh = cv.ChucDanh;
                    congviec.NoiLamViec = cv.Ten;
                    congviec.NgayDang = (DateTime)cv.NgayDang;
                    congviec.Mucluong = cv.MucLuong;
                    congviec.MaCongTy = (int)cv.MaNhaTuyenDung;
                    congviec.MaNoiLamViec = (int)cv.MaTinhThanh;
                    //if (cv.Luong != null)
                    //{
                    //    congviec.Luong = (int)cv.Luong;
                    //}
                    //if (cv.SoNamKN != null)
                    //{
                    //    congviec.SoNamKN = (int)cv.SoNamKN;
                    //}
                    DSCongViec.Add(congviec);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return DSCongViec;
        }


        public static List<ChiTietCongViec_DTO> DanhSachCacCongViecThuocNoiLamViec(string Mnlv)
        {
            var list = dt.spDanhSachCacCongViecThuocNoiLamViec(Mnlv);
            List<ChiTietCongViec_DTO> DSCongViec = new List<ChiTietCongViec_DTO>();
            try
            {
                foreach (var cv in list)
                {
                    ChiTietCongViec_DTO congviec = new ChiTietCongViec_DTO();
                    congviec.MaCongViec = cv.MaCongViec;
                    congviec.TenCongTy = cv.TenCongTy;
                    congviec.ChucDanh = cv.ChucDanh;
                    congviec.NoiLamViec = cv.Ten;
                    congviec.NgayDang = ((DateTime)cv.NgayDang).Date;
                    congviec.Mucluong = cv.MucLuong;
                    congviec.MaCongTy = (int)cv.MaNhaTuyenDung;
                    congviec.MaNoiLamViec = (int)cv.MaTinhThanh;
                    DSCongViec.Add(congviec);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return DSCongViec;
        }

        public static List<ChiTietCongViec_DTO> ChiTietCongViec(string Mcv)
        {
            try
            {
                List<ChiTietCongViec_DTO> ctcv = new List<ChiTietCongViec_DTO>();
                var temp = dt.spChiTietCongViec(Mcv);
                foreach (var cv in temp)
                {
                    ChiTietCongViec_DTO congviec = new ChiTietCongViec_DTO();
                    congviec.MaCongViec = cv.MaCongViec;
                    congviec.ChucDanh = cv.ChucDanh;
                    congviec.MoTaCongViec = cv.TomTat;
                    congviec.YeuCauCongViec = cv.NoiDung;
                    congviec.NgayDang = (DateTime)cv.NgayDang;
                    congviec.NgayHetHanDang = (DateTime)cv.NgayHetHan;
                    congviec.Mucluong = cv.MucLuong;
                    congviec.NoiLamViec = cv.NoiLamViec;
                    congviec.TenCongTy = cv.TenCongTy;
                    congviec.MaLoaiHinhCongViec = (int)cv.MaLoaiHinhCongViec;
                    congviec.NamKinhNghiem = cv.NamKinhNghiem;
                    //congviec.MoTaCongTy = cv.GioiThieu;
                    congviec.TenLoaiHinhCongViec = cv.TenLoaiHinh;
                    congviec.CapBac = cv.TenCapBac;
                    //congviec.DiaChi = cv.DiaChi;
                    congviec.NgonNgu = cv.NgonNgu;
                    //congviec.Email = cv.Email;
                    //congviec.NguoiLienHe = cv.NguoiLienHe;
                    //congviec.Logo = cv.Logo;
                    congviec.SoLuotXem = (int)cv.SoLuotXem;
                    if (cv.Luong != null)
                    {
                        congviec.Luong = (int)cv.Luong;
                    }
                    if (cv.SoNamKN != null)
                    {
                        congviec.SoNamKN = (int)cv.SoNamKN;
                    }
                    ctcv.Add(congviec);
                    CONGVIEC c = new CONGVIEC();
                }
                return ctcv;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public static IEnumerable DanhSachNoiLamViec()
        {
            return dt.spDanhSachNoiLamViec().AsEnumerable();
        }

        public static void CapNhatSoLuotXem(int SoLuotXem, string Mcv)
        {
            dt.spCapNhatSoLuotXem(SoLuotXem, Mcv);
        }

        public static List<ChiTietCongViec_DTO> TimKiemNhanhDanhSachCacCongViecThuocNhaTuyenDung(string Mct)
        {
            List<ChiTietCongViec_DTO> DSCongViec = new List<ChiTietCongViec_DTO>();
            var list = dt.spTimKiemNhanhDanhSachCacCongViecThuocNhaTuyenDung(Mct);
            try
            {
                foreach (var cv in list)
                {
                    ChiTietCongViec_DTO congviec = new ChiTietCongViec_DTO();
                    congviec.MaCongViec = cv.MaCongViec;
                    congviec.TenCongTy = cv.TenCongTy;
                    congviec.ChucDanh = cv.ChucDanh;
                    congviec.NoiLamViec = cv.Ten;
                    congviec.NgayDang = (DateTime)cv.NgayDang;

                    congviec.MaCongTy = (int)cv.MaNhaTuyenDung;
                    congviec.MaNoiLamViec = (int)cv.MaTinhThanh;
                    congviec.MaLoaiHinhCongViec = (int)cv.MaLoaiHinhCongViec;
                    congviec.Mucluong = cv.MucLuong;
                    congviec.MaCapBac = (int)cv.MaCapBac;
                    if (cv.Luong != null)
                    {
                        congviec.Luong = (int)cv.Luong;
                    }
                    if (cv.SoNamKN != null)
                    {
                        congviec.SoNamKN = (int)cv.SoNamKN;
                    }

                    if (cv.MaNganhNghe != null)
                    {
                        congviec.MaNganhNghe = (int)cv.MaNganhNghe;
                    }
                    DSCongViec.Add(congviec);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return DSCongViec;
        }

        public static List<ChiTietCongViec_DTO> TimKiemNhanh(int Mng, int Mnlv)
        {
            List<ChiTietCongViec_DTO> DSCongViec = new List<ChiTietCongViec_DTO>();
            var list = dt.spTimKiemNhanh(Mng, Mnlv);
            try
            {
                foreach (var cv in list)
                {
                    ChiTietCongViec_DTO congviec = new ChiTietCongViec_DTO();
                    congviec.MaCongViec = cv.MaCongViec;
                    congviec.TenCongTy = cv.TenCongTy;
                    congviec.ChucDanh = cv.ChucDanh;
                    congviec.NoiLamViec = cv.Ten;
                    congviec.NgayDang = (DateTime)cv.NgayDang;
                    congviec.Mucluong = cv.MucLuong;
                    congviec.MaCongTy = (int)cv.MaNhaTuyenDung;
                    congviec.MaNoiLamViec = (int)cv.MaTinhThanh;
                    congviec.MaLoaiHinhCongViec = (int)cv.MaLoaiHinhCongViec;
                    congviec.MaNganhNghe = (int)cv.MaNganhNghe;
                    congviec.MaCapBac = (int)cv.MaCapBac;
                    congviec.MoTaCongViec = cv.TomTat;
                    congviec.YeuCauCongViec = cv.NoiDung;
                    if (cv.Luong != null)
                    {
                        congviec.Luong = (int)cv.Luong;
                    }
                    if (cv.SoNamKN != null)
                    {
                        congviec.SoNamKN = (int)cv.SoNamKN;
                    }
                    DSCongViec.Add(congviec);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return DSCongViec;
        }

        public static IEnumerable CongViecCapGap()
        {
            return dt.spCongViecMoi().AsEnumerable();
        }

        public static IEnumerable CongViecTheoNgayDang()
        {
            return dt.spCongViecTheoNgayDang().AsEnumerable();
        }

        public static IEnumerable CongViecTheoLuong()
        {
            return dt.spCongViecTheoLuong().AsEnumerable();
        }

        public static IEnumerable DanhSachCacLoaiHinhCongViec()
        {
            return dt.spDanhSachCacLoaiHinhCongViec().AsEnumerable();
        }

        public static IEnumerable DanhSachCacCapBac()
        {
            return dt.spDanhSachCacCapBac().AsEnumerable();
        }

        public static void HuyCongViec(string Mcv)
        {
            dt.spXoaCongViec(Mcv);
        }


        public static List<ChiTietCongViec_DTO> LayCongViecDaLuu(int UserID)
        {
            List<ChiTietCongViec_DTO> listcongviec = new List<ChiTietCongViec_DTO>();

            var list = dt.spLayCongViecDaXem(UserID);
            foreach (var congviec in list)
            {
                ChiTietCongViec_DTO cv = new ChiTietCongViec_DTO();
                cv.ChucDanh = congviec.chucdanh;
                cv.MaCongViec = congviec.macongviec;
                cv.Mucluong = congviec.MucLuong;
                cv.NgayDang = DateTime.Parse(congviec.thoigian.ToString());
                cv.TenCongTy = congviec.ten;
                cv.MaCongTy = congviec.MaNhaTuyenDung;
                cv.TrangThai = (int)congviec.TrangThai;
                listcongviec.Add(cv);
            }
            return listcongviec;
        }

        public static void LayMaCongTyTuMaCongViec(string Mcv, ref string Mct, ref string TrangThai)
        {
            dt.spLayMaCongTyTuMaCongViec(Mcv, ref Mct, ref TrangThai);
        }

        public static IEnumerable DanhSachCacTinSaiPham()
        {
            return dt.spDanhSachCacTinSaiPham().AsEnumerable();
        }

        public static void ChoPhepDangLaiTin(string Mcv)
        {
            dt.spChoPhepDangLaiTin(Mcv);
        }

        public static List<ChiTietCongViec_DTO> ChiTietCongViecSaiPham(string Mcv)
        {
            try
            {
                List<ChiTietCongViec_DTO> ctcv = new List<ChiTietCongViec_DTO>();
                var temp = dt.spChiTietCongViecSaiPham(Mcv);
                foreach (var cv in temp)
                {
                    ChiTietCongViec_DTO congviec = new ChiTietCongViec_DTO();
                    congviec.MaCongViec = cv.MaCongViec;
                    congviec.ChucDanh = cv.ChucDanh;
                    congviec.MoTaCongViec = cv.TomTat;
                    congviec.YeuCauCongViec = cv.NoiDung;
                    congviec.NgayDang = (DateTime)cv.NgayDang;
                    congviec.NgayHetHanDang = (DateTime)cv.NgayHetHan;
                    congviec.Mucluong = cv.MucLuong;
                    congviec.NoiLamViec = cv.NoiLamViec;
                    congviec.TenCongTy = cv.TenCongTy;
                    congviec.MaLoaiHinhCongViec = (int)cv.MaLoaiHinhCongViec;
                    congviec.NamKinhNghiem = cv.NamKinhNghiem;
                    //congviec.MoTaCongTy = cv.GioiThieu;
                    congviec.TenLoaiHinhCongViec = cv.TenLoaiHinh;
                    congviec.CapBac = cv.TenCapBac;
                    //congviec.DiaChi = cv.DiaChi;
                    congviec.NgonNgu = cv.NgonNgu;
                    //congviec.Email = cv.Email;
                    //congviec.NguoiLienHe = cv.NguoiLienHe;
                    //congviec.Logo = cv.Logo;
                    congviec.SoLuotXem = (int)cv.SoLuotXem;
                    if (cv.Luong != null)
                    {
                        congviec.Luong = (int)cv.Luong;
                    }
                    if (cv.SoNamKN != null)
                    {
                        congviec.SoNamKN = (int)cv.SoNamKN;
                    }
                    ctcv.Add(congviec);
                    CONGVIEC c = new CONGVIEC();
                }
                return ctcv;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
